using Boo.Lang;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

[Serializable]
public class DragRigidbodyoneround : MonoBehaviour
{
	[Serializable]
	[CompilerGenerated]
	internal sealed class _0024DragObject_0024342 : GenericGenerator<object>
	{
		internal float _0024distance_0024348;

		internal DragRigidbodyoneround _0024self__0024349;

		public _0024DragObject_0024342(float distance, DragRigidbodyoneround self_)
		{
			_0024distance_0024348 = distance;
			_0024self__0024349 = self_;
		}

		public override IEnumerator<object> GetEnumerator()
		{
			return new _0024(_0024distance_0024348, _0024self__0024349);
		}
	}

	[Serializable]
	[CompilerGenerated]
	internal sealed class _0024destroy_0024350 : GenericGenerator<WaitForSeconds>
	{
		internal DragRigidbodyoneround _0024self__0024352;

		public _0024destroy_0024350(DragRigidbodyoneround self_)
		{
			_0024self__0024352 = self_;
		}

		public override IEnumerator<WaitForSeconds> GetEnumerator()
		{
			return new _0024(_0024self__0024352);
		}
	}

	[Serializable]
	[CompilerGenerated]
	internal sealed class _0024ld_0024353 : GenericGenerator<WaitForSeconds>
	{
		internal DragRigidbodyoneround _0024self__0024355;

		public _0024ld_0024353(DragRigidbodyoneround self_)
		{
			_0024self__0024355 = self_;
		}

		public override IEnumerator<WaitForSeconds> GetEnumerator()
		{
			return new _0024(_0024self__0024355);
		}
	}

	public Rigidbody body;

	public Transform tr;

	public Transform box;

	public GameObject launcher;

	public spin blade;

	public Rigidbody bey;

	public float spring;

	public float damper;

	public float drag;

	public float angularDrag;

	public float distance;

	public bool attachToCenterOfMass;

	public float speed;

	public float speedo;

	public float xx;

	public float xxx;

	public float XD;

	public bool LeftHanded;

	public int fstart;

	public Camera mainCamera;

	private SpringJoint springJoint;

	private SpringJoint springJoint1;

	public winlosedrawoneround wld;

	public DragRigidbodyoneround()
	{
		spring = 50f;
		damper = 5f;
		drag = 10f;
		angularDrag = 5f;
		distance = 0.2f;
		XD = 190.8f;
	}

	public void Start()
	{
		if (PlayerPrefs.GetInt("LeftHanded") == 1)
		{
			LeftHanded = true;
		}
		GameObject gameObject = new GameObject("Rigidbody dragger");
		Rigidbody rigidbody = gameObject.AddComponent<Rigidbody>() as Rigidbody;
		destroy destroy = gameObject.AddComponent<destroy>() as destroy;
		springJoint1 = (gameObject.AddComponent<SpringJoint>() as SpringJoint);
		Vector3 position = transform.position;
		xxx = position.x;
		body = GetComponent<Rigidbody>();
		tr = transform;
		StartCoroutine(this.destroy());
	}

	public void Update()
	{
		speedo = body.velocity.magnitude * 19f + 0.1f;
		if (fstart == 0)
		{
			blade.spinvelocity = (int)speed;
		}
		else
		{
			blade.spinvelocity = 50;
		}
		Vector3 position = tr.position;
		xx = position.x;
		if (!Input.GetMouseButtonDown(0))
		{
			return;
		}
		RaycastHit hitInfo = default(RaycastHit);
		if (Physics.Raycast(mainCamera.ScreenPointToRay(UnityEngine.Input.mousePosition), out hitInfo, 100f) && (bool)hitInfo.rigidbody && !hitInfo.rigidbody.isKinematic && !hitInfo.rigidbody.useGravity)
		{
			if (!springJoint)
			{
				StartCoroutine(this.destroy());
				GameObject gameObject = new GameObject("Rigidbody dragger");
				Rigidbody rigidbody = gameObject.AddComponent<Rigidbody>() as Rigidbody;
				destroy destroy = gameObject.AddComponent<destroy>() as destroy;
				springJoint = (gameObject.AddComponent<SpringJoint>() as SpringJoint);
				rigidbody.isKinematic = true;
			}
			springJoint.transform.position = hitInfo.point;
			if (attachToCenterOfMass)
			{
				Vector3 position2 = transform.TransformDirection(hitInfo.rigidbody.centerOfMass) + hitInfo.rigidbody.transform.position;
				position2 = springJoint.transform.InverseTransformPoint(position2);
				springJoint.anchor = position2;
			}
			else
			{
				springJoint.anchor = Vector3.zero;
			}
			springJoint.spring = spring;
			springJoint.damper = damper;
			springJoint.maxDistance = distance;
			springJoint.connectedBody = hitInfo.rigidbody;
			StartCoroutine("DragObject", hitInfo.distance);
		}
	}

	public IEnumerator DragObject(float distance)
	{
		return new _0024DragObject_0024342(distance, this).GetEnumerator();
	}

	public void LateUpdate()
	{
		if ((bool)springJoint && Input.GetMouseButtonUp(0))
		{
			blade.spin();
			StartCoroutine(wld.state());
			UnityEngine.Object.Destroy(launcher);
		}
		if (!(speedo <= speed))
		{
			speed = speedo * 1.1f;
		}
		if (!LeftHanded && !(xx <= xxx))
		{
			xxx = xx;
		}
		if (LeftHanded && !(xx >= xxx))
		{
			xxx = xx;
		}
		if (!LeftHanded)
		{
			if (!(xx >= xxx))
			{
				float x = xx;
				Vector3 position = transform.position;
				position.x = x;
				Vector3 vector2 = transform.position = position;
			}
			if (!(xx + 0.2f >= xxx))
			{
				fstart = 1;
				blade.spinvelocity = 50;
				blade.spin();
				if ((bool)wld)
				{
					StartCoroutine(wld.state());
				}
				UnityEngine.Object.Destroy(launcher);
			}
		}
		if (!LeftHanded)
		{
			return;
		}
		if (!(xx <= xxx))
		{
			float x2 = xx;
			Vector3 position2 = transform.position;
			position2.x = x2;
			Vector3 vector4 = transform.position = position2;
		}
		if (!(xx - 0.2f <= xxx))
		{
			fstart = 1;
			blade.spinvelocity = 50;
			blade.spin();
			if ((bool)wld)
			{
				StartCoroutine(wld.state());
			}
			UnityEngine.Object.Destroy(launcher);
		}
	}

	public IEnumerator destroy()
	{
		return new _0024destroy_0024350(this).GetEnumerator();
	}

	public IEnumerator ld()
	{
		return new _0024ld_0024353(this).GetEnumerator();
	}

	public void Main()
	{
	}
}
